package com.bailiban.aigou.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.bailiban.aigou.common.BaseAction;
import com.bailiban.aigou.entity.ProductType;
import com.bailiban.aigou.service.IProductTypeService;
import com.bailiban.aigou.utils.IconfontUtils;
import com.bailiban.aigou.utils.PageModel;

@Controller
@Scope("prototype")
@Namespace("/admin/productType")
public class ProductTypeAction extends BaseAction {
	
	@Autowired
	private IProductTypeService productTypeService;

	@Action(value = "list", results = {
		@Result(name = SUCCESS, location = SYS_JSP_BASEURL + "admin/product_type/list.jsp")
	})
	public String list(){
		HttpServletRequest request = ServletActionContext.getRequest();
		super.setPageNo(request.getParameter("pageNo"));
		super.setPageSize(request.getParameter("pageSize"));
		//去加载数据
		PageModel<ProductType> productTypePages = new PageModel<ProductType>();
		productTypePages.setPageNo(super.getPageNo());
		productTypePages.setPageSize(super.getPageSize());
		productTypePages = productTypeService.getProductTypes(productTypePages);
		request.setAttribute("productTypePages", productTypePages);
		
		return SUCCESS;
	}
	
	@Action(value = "addPage", results = {
		@Result(name = SUCCESS, location = SYS_JSP_BASEURL + "admin/product_type/add.jsp")
	})
	public String addPage(){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();	
			List<String> iconfonts = IconfontUtils.getIconfonts(request);
			request.setAttribute("iconfonts", iconfonts);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return SUCCESS;
	}
}
